package thermologic.core;

import java.io.Serializable;

/**
 * Represents a device with minimal
 * info: an id and a description
 * 
 * @author Mauricio
 */
public abstract class Device implements Serializable, Cloneable
{
    /**
     * Device id, a unique manufactured
     * serial id
     */
    private String id;
    
    /**
     * Device type
     */
    private DeviceType deviceType; 
    
    /**
     * Short text about the device functions
     */
    private String description;
    
    
    /**
     * Status of device
     */
    private DeviceStatus status;
    
    /**
     * Default constructor required for 
     * XML serialization 
     */
    protected Device()
    {
    }
    
    /**
     * Builds a device object with id and
     * description
     * 
     * @param id
     * @param description
     */
    protected Device(String id, DeviceType deviceType, String description,
            DeviceStatus status)
    {
        setId(id);
        setDeviceType(deviceType);
        setDescription(description);
        setStatus(status);
        
    }

    /**
     * @return the device id
     */
    public String getId()
    {
        return id;
    }

    /**
     * @return the device description
     */
    public String getDescription()
    {
        return description;
    }
    
    /**
     * @return the device status
     */
    public DeviceStatus getStatus()
    {
        final DeviceStatus inmutableStatus = status;
        return inmutableStatus;
    }
    
    /** Sets the id
     * 
     * @param id
     */
    public void setId(String id)
    {
        if(id == null || id.equals(""))
        {
            throw new IllegalArgumentException("Device id invalid");
        }
        this.id = id;
    }

    /**
     * Sets description
     * 
     * @param description
     */
    public void setDescription(String description)
    {
        this.description = description;
    }
    
    /**
     * Sets the device status
     * 
     * @param status
     */
    public void setStatus(DeviceStatus status)
    {
        if(status == null)
        {
            throw new IllegalArgumentException("the device status is null");
        }
        this.status = status;
    }

    /**
     * @return the device type
     */
    public DeviceType getDeviceType() {
        return deviceType;
    }

    /**
     * Set the device type
     * 
     * @param deviceType
     */
    public void setDeviceType(DeviceType deviceType)
    {
        if(deviceType == null)
        {
            throw new IllegalArgumentException("the device type is null");
        }
        this.deviceType = deviceType;
    }
}
